package ofc4j.util;

import ofc4j.model.elements.ScatterChart;
import ofc4j.model.elements.ScatterChart.Point;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.path.PathTrackingWriter;

public class ScatterChartPointConverter implements Converter {
    @Override
    @SuppressWarnings("unchecked")
    public boolean canConvert(Class c) {
        return ScatterChart.Point.class.isAssignableFrom(c);
    }

    @Override
    public void marshal(Object o, HierarchicalStreamWriter hsw, MarshallingContext ctxt) {
        PathTrackingWriter writer = (PathTrackingWriter) hsw;
        Point p = (Point) o;
        writer.startNode("x", p.getX().getClass());
        writer.setValue(p.getX().toString());
        writer.endNode();
        writer.startNode("y", p.getY().getClass());
        writer.setValue(p.getY().toString());
        writer.endNode();
    }

    @Override
    public Object unmarshal(HierarchicalStreamReader arg0, UnmarshallingContext arg1) {
        return null;
    }
}
